<!DOCTYPE html>
<html>

<head>
<title>添加代理</title>
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">

<%include("/common/include.html"){}%>
<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<style type="text/css">
	.required{
			display:inline-block;
			width: 30%;
		}
		label{
			text-align:right;
			width:90px;
			display:inline-block;
		}
</style>
</head>

<body>
	<div class="easyui-panel" style="width: 100%; padding: 30px 60px; border-width: 0px;">
		<div  style="margin:auto;width:100%">
			<form id="addOrgan" method="post" class="form">
			<input type="hidden" name="organIds" value="${organIds!}"/>
				<div style="margin-bottom: 20px">
					<label class="label-top">${organ.levelInfo.parentName! }:</label>
					<div class="required">
						<input class="easyui-textbox theme-textbox-radius" style="width: 100%;" value="${organ.name! }" data-options="disabled:true">
					</div>
					<span style="color:red">*必填项</span>
					<input type="hidden" name="organization.parentIds" value="${organ.ids! }" />
	
					<label class="label-top" style="margin-left:30px">${organ.levelInfo.name! }:</label>
					<div class="required">
						<input   id="organizationname1"  class="easyui-textbox theme-textbox-radius" style="width: 100%;" name="organization.name">
					</div>
					<span style="color:red">*必填项</span>
				</div>
				<div style="margin-bottom: 20px">
				
					<label class="label-top">${organ.levelInfo.parentManger! }:</label>
					<input id="marketManger" type="text" readonly style="width: 250px; height: 32.4px;padding-left:10px;border-radius:4px;" onclick="showMenu(); return false;" class="textbox" />
					<!-- <span style="color:red">*必填项</span> -->
					<input id="mangerids" type="hidden" name="organization.mangerIds" style="width: 100%;" >
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					
					<label class="label-top" style="margin-left:30px">门店编号:</label>
					<div class="required">
					<input  id="organizationname9" class="easyui-textbox theme-textbox-radius" style="width: 100%;" name="organization.mdbh">
					</div>
					<span style="color:red">*必填项</span>   
					<!-- <label class="label-top" style="margin-left:48px">${organ.levelInfo.priceTable! }:</label>
					<input id="priceTable" type="text" readonly style="width: 228px; height: 32.4px;padding-left:10px;border-radius:4px;" onclick="showPriceTable(); return false;" class="textbox"/>
					<span style="color:red">*必填项</span>
					<input id="priceIds" type="hidden" name="organization.priceIds" style="width: 100%;" > -->
					
				</div>
				<div style="margin-bottom: 20px">
				
					<label class="label-top">${organ.levelInfo.mangerName! }:</label>
					<div class="required">
						<input   id="organizationname4" class="easyui-textbox theme-textbox-radius" style="width: 100%;" name="user.name">
					</div>
					<span style="color:red">*必填项</span>
					<label class="label-top" style="margin-left:30px">${organ.levelInfo.mangerUsername! }:</label>
					<div class="required">
						<input   id="organizationname5" class="easyui-textbox theme-textbox-radius" style="width: 100%;" name="user.username">
					</div>
					<span style="color:red">*必填项</span>
				</div>
				<div style="margin-bottom: 20px">
				
					<label class="label-top">${organ.levelInfo.mangerPhone! }:</label>
					<div class="required">
						<input  id="organizationname6" class="easyui-textbox theme-textbox-radius" style="width: 100%;" name="user.mobile">
					</div>
					<span style="color:red">*必填项</span>
					
					<label class="label-top" style="margin-left:30px">${organ.levelInfo.area! }:</label>
					<input id="xzqh_text" type="text" readonly style="width: 250px; height: 32.4px;padding-left:10px;border-radius:4px;" onclick="showXZQH(); return false;" class="textbox"/>
					<span style="color:red">*必填项</span>
					<input type="hidden" name="organization.xzqh" id="xzqh"/>
				</div>
				<div style="margin-bottom: 20px">    
					<label class="label-top">${organ.levelInfo.time! }:</label>
					<div class="required">
						<input  id="organizationname8" name="organization.kyTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="width:100%;" data-options="editable: false"/>
					</div>
					<span style="color:red">*必填项</span>
					
					<label class="label-top" style="margin-left:30px">地址:</label>
					<div class="required">
						<input class="easyui-textbox theme-textbox-radius" style="width: 100%;" name="organization.address">
					</div>
					<span style="color:red"></span>
				</div>
				
				<div style="margin-bottom: 20px"> 
					
					
					<label class="label-top"  >设置权限:</label>
					<a href="#" class="easyui-linkbutton button-blue button-sm" onclick="showRight();">
						<i class="fa fa-check"></i> 点击设置权限
					</a>
				</div>
				<div id="nodes"></div>
			</form>
		</div>

	</div>
	<div id="menuContent" class="menuContent" style="display: none; position: absolute;">
		<ul id="marketMangerTree" class="ztree" style="margin-top: 0;width:228px;"></ul>
	</div>
	
	<div id="xzqhContent" class="menuContent" style="display: none; position: absolute;">
		<ul id="xzqh_tree" class="ztree" style="margin-top: 0;width:228px;"></ul>
	</div>
	
	<div id="priceContent" class="menuContent" style="display: none; position: absolute;">
		<ul id="price_tree" class="ztree" style="margin-top: 0;width:228px;"></ul>
	</div>

	<div id="win" class="easyui-window" title="设置权限" style="width: 600px; height: 400px"
		data-options="iconCls:'icon-save',modal:true,closed:true,cls:'theme-panel-orange'">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'"><%include("/organization/rightTree.html"){}%></div>
		</div>
	</div>
	<script type="text/javascript">
		//@ sourceURL=mmm.js
		function showRight() {
			$('#win').window('open');
			var rightTree = $.fn.zTree.getZTreeObj("rightTree");
			var nodes = rightTree.getNodes();
			if(nodes.length == 0){
				parent.slideMsg("请联系管理员设置通用权限！");
			}
		}
		var $form = $('#addOrgan');

		var submitNow = function($dialog, $grid, $tree, $pjq) {
			var rightTree = $.fn.zTree.getZTreeObj("rightTree");
			var checkedNode = rightTree.getCheckedNodes(false);//获取取消的节点
			for (var i = 0; i < checkedNode.length; i++) {
				var id = checkedNode[i].id;
				$("#nodes").append("<input type='hidden' name='ztreeNodeList["+i+"].id' value='"+id+"'/>");
			}
			
			
			
			var organizationname  = $("#organizationname1").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填写门店！");
				return false;
			}
			
		
			
			
			var organizationname  = $("#organizationname4").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填写店长姓名！");
				return false;
			}
			
			
			var organizationname  = $("#organizationname5").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填写店长用户名！");
				return false;
			}
			
			
			var organizationname  = $("#organizationname6").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填写店长手机号！");
				return false;
			}
			
			
		/* 	var organizationname  = $("#xzqh_text").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填写行政区划！");
				return false;
			} */
			
			
			var organizationname  = $("#organizationname8").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填开业时间！");
				return false;
			}
			
			
			var organizationname  = $("#organizationname9").val();
			if(organizationname==null||organizationname==''){
				$.alert(parent.$, "请填门店编号！");
				return false;
			}
			
			
			
			
			var url = "${cxt!}/organization/addOrgan";
			$.post(url, sy.serializeObject($form), function(result) {
				if (result.code == '200') {
					 var curNode = $tree.getSelectedNodes();
					if (curNode.length > 0) {
						curNode[0].isParent = true;
						$tree.reAsyncChildNodes(curNode[0], "refresh");
					} 
					$grid.datagrid('reload');
					$.slideMsg("添加成功！", $pjq);
					$dialog.dialog('destroy');
				} else {
					$.messager.alert('错误', result.msg, 'error');
				}
			}, 'json');
		};
		var submitForm = function($dialog, $grid, $tree, $pjq) {
			submitNow($dialog, $grid, $tree, $pjq);
			// 					$form.isValid(function(isValied){
			// 						if(isValied){
			// 							submitNow($dialog, $grid, $pjq);
			// 						}
			// 					});
		};

		var setting = {
			async : {
				enable : true,
				url : '${cxt!}/organization/mangerSelect',
				autoParam : [ "id=ids" ],//, "name=n", "level=lv"
				otherParam : {
					"organIds" : "${organ.ids! }"
				},
				type : "post"
			},
			view : {
				dblClickExpand : false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				beforeClick : beforeClick,
				onClick : onClick
			}
		};
		function beforeClick(treeId, treeNode) {
			var check = (treeNode && !treeNode.isParent);
			if (!check)
				parent.slideMsg("只能选择用户...");
			return check;
		}

		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("marketMangerTree");
			var name = "";
			var sNodes = zTree.getSelectedNodes();
			if (sNodes.length > 0) {
				name = sNodes[0].name;
			}
			var cityObj = $("#marketManger");
			cityObj.attr("value", name);
			$("#mangerids").attr("value", treeNode.id);
		}
		function showMenu() {
			var cityObj = $("#marketManger");
			var cityOffset = $("#marketManger").offset();
			$("#menuContent").css({
				left : cityOffset.left + "px",
				top : cityOffset.top + cityObj.outerHeight() + "px"
			}).slideDown("fast");

			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn"
					|| event.target.id == "menuContent" || $(event.target)
					.parents("#menuContent").length > 0)) {
				hideMenu();
			}
		}
		$.fn.zTree.init($("#marketMangerTree"), setting);
	</script>
	<script type="text/javascript">
	var priceSetting = {
			async : {
				enable : true,
				url : '${cxt!}/organization/priceSelect',
				autoParam : [ "id=ids" ],//, "name=n", "level=lv"
				otherParam : {
					"organIds" : "${organ.ids! }"
				},
				type : "post"
			},
			view : {
				dblClickExpand : false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				beforeClick : price_beforeClick,
				onClick : price_onClick
			}
		};
		function price_beforeClick(treeId, treeNode) {
			var check = (treeNode && !treeNode.isParent);
			if (!check)
				parent.slideMsg("只能选择价格表...");
			return check;
		}

		function price_onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("price_tree");
			var name = "";
			var sNodes = zTree.getSelectedNodes();
			if (sNodes.length > 0) {
				name = sNodes[0].name;
			}
			var cityObj = $("#priceTable");
			cityObj.attr("value", name);
			$("#priceIds").attr("value", treeNode.id);
		}
		function showPriceTable() {
			var cityObj = $("#priceTable");
			var cityOffset = $("#priceTable").offset();
			$("#priceContent").css({
				left : cityOffset.left + "px",
				top : cityOffset.top + cityObj.outerHeight() + "px"
			}).slideDown("fast");

			$("body").bind("mousedown", onBodyDownPrcie);
		}
		function hidePriceTable() {
			$("#priceContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDownPrcie);
		}
		function onBodyDownPrcie(event) {
			if (!(event.target.id == "menuBtn"
					|| event.target.id == "priceContent" || $(event.target)
					.parents("#priceContent").length > 0)) {
				hidePriceTable();
			}
		}
		$.fn.zTree.init($("#price_tree"), priceSetting);
	</script>
	<script type="text/javascript">
		var xzqhSetting = {
			async : {
				enable : true,
				url : '${cxt!}/common/xzqhTree2?ids=${organ.xzqh.ids! }',
				autoParam : [ "id=ids" ],//, "name=n", "level=lv"
				type : "post"
			},
			view : {
				dblClickExpand : false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				onClick : xzqh_onClick,
			}
		};
		
		function xzqh_onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("xzqh_tree");
			var path = "";
			var sNodes = zTree.getSelectedNodes();
			if (sNodes.length > 0) {
				var node = sNodes[0].getPath();
				for(var i =0;i<node.length;i++){
					//path += node[i].name + "/"
					path=node[i].name
				}
			}
			var cityObj = $("#xzqh_text");
			cityObj.attr("value", path);
			$("#xzqh").attr("value", treeNode.id);
		}
		function showXZQH() {
			var cityObj = $("#xzqh_text");
			var cityOffset = $("#xzqh_text").offset();
			$("#xzqhContent").css({
				left : cityOffset.left + "px",
				top : cityOffset.top + cityObj.outerHeight() + "px"
			}).slideDown("fast");

			$("body").bind("mousedown", onBodyDownXZQH);
		}
		function hideXZQH() {
			$("#xzqhContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDownXZQH);
		}
		function onBodyDownXZQH(event) {
			if (!(event.target.id == "menuBtn"
					|| event.target.id == "xzqhContent" || $(event.target)
					.parents("#xzqhContent").length > 0)) {
				hideXZQH();
			}
		}
		$.fn.zTree.init($("#xzqh_tree"), xzqhSetting);
		
	</script>
</body>
</html>